<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>客户对账单打印</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <script src="/chineseMoney.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <h3 style="text-align: center"><span class="customer"></span>-客户对账单</h3>
    <br/>
    <table width="100%">
        <tr>
            <td width="25%">客户名称：</td><td width="75%"><span class="customer"></span></td>
        </tr>
        <tr>
            <td width="25%">供货方：</td><td width="75%"><span class="company"></span></td>
        </tr>
        <tr>
            <td width="25%">对账日期：</td><td width="75%"><span class="supplyDate"></span></td>
        </tr>
        <tr>
            <td width="25%">餐别：</td><td width="75%"><span class="mealsType"></span></td>
        </tr>
    </table>
    <br/>
    <table style="width: 100%;" class="printTable">
        <thead style="border: 1px solid">
        <td width="10%">序号</td>
        <td width="15%">配送日期</td>
        <td width="20%">单据编号</td>
        <td width="15%">餐别</td>
        <td width="15%">金额</td>
        <td width="15%">订单状态</td>
        </thead>
        <tbody id="content">
        </tbody>
    </table>
    <table style="width: 100%;" class="printTable">
        <tr>
            <td width="25%">合计人民币小写：</td><td width="75%"><span class="lowerTotal"></span></td>
        </tr>
        <tr>
            <td width="25%">合计人民币大写：</td><td width="75%"><span class="upperTotal"></span></td>
        </tr>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var backAddress = params.backAddress;
    var beginSupplyDate = params.beginSupplyDate;
    var endSupplyDate = params.endSupplyDate;
    var customer = params.customerId;
    var customerName = params.customerName;
    var companyName = params.companyName;
    var mealsTypeId = params.mealsTypeId;
    var mealsTypeName = params.mealsTypeName;
    function print() {
        $("#receiptPrintArea0").printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
        url: backAddress + "/api/financial/queryCustomerCheck",
        type: "post",
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data : JSON.stringify({
            "beginSupplyDate" : beginSupplyDate,
            "endSupplyDate" : endSupplyDate,
            "customerId" : customer,
            "mealsTypeId" : mealsTypeId,
            "pageNo" : 1,
            "pageSize" : 2000
        }),
        success: function (data) {
            console.log(data)
            $(".supplyDate")[0].innerText = beginSupplyDate + '至' + endSupplyDate;
            $(".customer")[0].innerText = customerName;
            $(".customer")[1].innerText = customerName;
            $(".company")[0].innerText = companyName;
            $(".mealsType")[0].innerText = mealsTypeName;
            var str = '' ;
            var total = 0 ;
            for (var i = 0 ; i < data.data.list.length ; i++) {
                str = "<tr><td width=\"10%\">" + (i + 1) + "</td>" +
                    "<td width=\"15%\">" + data.data.list[i].supplyDate + "</td>" +
                    "<td width=\"20%\">" + data.data.list[i].id + "</td>" +
                    "<td width=\"15%\">" + data.data.list[i].mealsTypeName + "</td>" +
                    "<td width=\"15%\">" + data.data.list[i].amountOfMoney + "</td>" +
                    "<td width=\"15%\">" + data.data.list[i].status + "</td></tr>" ;
                $("#content").append($(str));
                total += data.data.list[i].amountOfMoney ;
            }

            $(".lowerTotal")[0].innerText = total ;
            $(".upperTotal")[0].innerText = Arabia_to_Chinese(total + '') ;
            print()
        },
        error: function (status) {
            alert(status)
        }
    })
</script>
</body>
</html>